<template>
  <div class="os-main">
    <ConfigForm v-model="dataForm" :config="config" ref="configFormRef" />

    <el-button type="primary" @click="openJson">查看表单数据</el-button>

    <el-drawer v-model="drawerVisiable" title="数据视图" :direction="'rtl'" size="40%">
      <CodeView :code-json="JSON.stringify(dataForm, null, '\t')"></CodeView>
    </el-drawer>
  </div>
</template>

<script lang="ts" setup>
import type { Config } from '@/components/ConfigForm'
import { ref, computed } from 'vue';
import CodeView from '@/components/CodeView/index.vue'
import ConfigForm from '@/components/ConfigForm/index'

/**ConfigForm绑定对象 */
const dataForm = ref<ObjectAny>({})

/**ConfigForm配置 */
const config = ref<Config>({
  mode: 'add',
  formProps: {},
  rowProps: {},
  columns: [
    { prop: 'demo1', label: '基础用法', type: 'timeSelect' },
    { prop: 'demo2', label: '范围与步长', type: 'timeSelect', props: { start: '08:30', step: '00:15', end: '18:30' } },
    { prop: 'demo3', label: '时间格式', type: 'timeSelect', props: { format: 'hh:mm A' } },
    { prop: 'demo4', label: '起始时间', type: 'timeSelect', props: { maxTime: computed(() => dataForm.value.demo5) } },
    { prop: 'demo5', label: '结束时间', type: 'timeSelect', props: { minTime: computed(() => dataForm.value.demo4) } },
  ]
})

// 数据视图
const drawerVisiable = ref(false)
const openJson = () => {
  drawerVisiable.value = true
}
</script>